//
//  JiaoYiMMTableViewCell.m
//  DBAChain
//
//  Created by Evan on 2018/9/6.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "JiaoYiMMTableViewCell.h"
#import <Masonry.h>
#import "CommonData.h"
#import "JiaoYiFromView.h"

@implementation JiaoYiMMTableViewCell{
    CGFloat tab1xx;
    CGFloat tab2xx;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)initUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIView *viewTop = [[UIView alloc]init];
    [self addSubview:viewTop];
    [viewTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.height.offset(101);
    }];
    viewTop.backgroundColor = COLOR_Background_black;
    
    UIView *viewBottom = [[UIView alloc]init];
    [self addSubview:viewBottom];
    [viewBottom mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.bottom.offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.top.mas_equalTo(viewTop.mas_bottom).offset(0);
    }];
    viewBottom.backgroundColor = [UIColor whiteColor];
    
    [self viewCenter];
    [self segmCheck];
    [self segmCheckIMG];
    [self viewJY];
    
}

-(UIView*)viewCenter{
    if (!_viewCenter) {
        _viewCenter = [[UIView alloc]init];
        [self addSubview:_viewCenter];
        [_viewCenter mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(15);
            make.right.offset(-15);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-10);
            make.top.mas_equalTo(self.mas_top).offset(5);
        }];
        _viewCenter.backgroundColor = [UIColor whiteColor];
        
        _viewCenter.layer.cornerRadius = 10;
        
        _viewCenter.layer.shadowColor = [UIColor blackColor].CGColor;
        //        阴影的透明度
        _viewCenter.layer.shadowOpacity = 0.3f;
        //        阴影的圆角
        _viewCenter.layer.shadowRadius = 4.0f;
    }
    return _viewCenter;
}

#pragma mark - Segm

-(UIImageView*)segmCheckIMG{
    if (!_segmCheckIMG) {
        _segmCheckIMG = [[UIImageView alloc]init];
        [self.viewCenter addSubview:_segmCheckIMG];
        NSLog(@"%f",self.viewCenter.frame.size.width);
        NSLog(@"%f",KScreenWidth/2);
        tab1xx = ((KScreenWidth-15)/3-35)/3;
        tab2xx = (KScreenWidth-15)/3+ tab1xx - 5;
        _segmCheckIMG.frame = CGRectMake(tab1xx, 45, 60, 2);
        _segmCheckIMG.image = [UIImage imageNamed:@"矩形Line"];
    }
    return _segmCheckIMG;
}

-(UISegmentedControl*)segmCheck{
    if (!_segmCheck) {
        _segmCheck = [[UISegmentedControl alloc]initWithItems:@[@"买入GTE",@"卖出GTE",@"订单详情"]];
        [self.viewCenter addSubview:_segmCheck];
        [_segmCheck mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.viewCenter);
            make.top.mas_equalTo(self.viewCenter).offset(10);
            make.height.offset(40);
            make.width.mas_equalTo(self.viewCenter);
        }];
        _segmCheck.tintColor = [UIColor clearColor];
        NSDictionary *selected = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:LCFromRGB(240, 92, 164)};
        //定义未选中状态下的样式normal，类型为字典
        NSDictionary *normal = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:LCFromRGB(51, 51, 51)};
        [_segmCheck setTitleTextAttributes:normal forState:UIControlStateNormal];
        [_segmCheck setTitleTextAttributes:selected forState:UIControlStateSelected];
        
        _segmCheck.selectedSegmentIndex = 0;
        [_segmCheck addTarget:self action:@selector(segmentValueChanged:)forControlEvents:UIControlEventValueChanged];
    }
    return _segmCheck;
}

-(void)segmentValueChanged:(UISegmentedControl*)sender{
    if(sender.selectedSegmentIndex == 0){
        [UIView animateWithDuration:0.3 animations:^{
            self.segmCheckIMG.frame = CGRectMake(self->tab1xx, 45, 60, 2);
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            self.segmCheckIMG.frame = CGRectMake(self->tab2xx, 45, 60, 2);
        }];
    }
}

#pragma mark - 买卖表单view

-(JiaoYiFromView*)viewJY{
    if (!_viewJY) {
        _viewJY = [[[NSBundle mainBundle] loadNibNamed:@"JiaoYiFromView" owner:nil options:nil] objectAtIndex:0];
        [self.viewCenter addSubview:_viewJY];
        [_viewJY mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.viewCenter).offset(30);
            make.right.mas_equalTo(self.viewCenter).offset(-30);
            make.top.mas_equalTo(self.viewCenter).offset(60);
            make.height.offset(300);
        }];
        
        [_viewJY initUI];
//        _viewJY.labelGET.text = @"5.241571310 GTE";
    }
    return _viewJY;
}


@end
